package com.itheima.d1_thread_api;

/**
 * 目标：掌握Thread的常用方法。
 */
public class ThreadTest1 {
    public static void main(String[] args) throws InterruptedException {

        Thread thread = Thread.currentThread();
        System.out.println(thread.getName());

        thread.setName("樊凯");
        System.out.println(thread.getName());

        MyThread myThread = new MyThread("樊凯");
        myThread.start();

        new Thread(new Runnable() {
            @Override
            public void run() {
                //这里无法获取线程的getName获取名称，因为当前是Runnable
                Thread thread1 = Thread.currentThread();
                System.out.println(thread1.getName());
            }
        }, "樊凯").start();

        new Thread(() -> {
            Thread thread2 = Thread.currentThread();
            System.out.println(thread2.getName());
        }
        ,"樊凯");
    }
}

class MyThread extends Thread {
    public MyThread(String name) {
        super(name);
    }

    @Override
    public void run() {
        String name = getName();

        System.out.println(name);
    }
}
